<%--
  Created by IntelliJ IDEA.
  User: 86186
  Date: 2022/3/20
  Time: 19:02
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>${requestScope.viewtype=="modify"?"学员信息修改":"学员新增"}</title>
</head>
<body>
<%@include file="common/top.jsp"%>
<!--/. NAV TOP  -->
<%@include file="common/left.jsp"%>
<%@include file="common/model.jsp"%>

<div id="wrapper">
  <div id="page-wrapper" >
    <div id="page-inner">
      <div class="row">
        <div class="col-md-12">
          <h1 class="page-header">
            某某学校 <small>${requestScope.viewtype=="modify"?"学员信息修改":"学员新增"}</small>
          </h1>
        </div>
      </div>
      <!-- /. ROW  -->
      <div class="row">
        <div class="col-lg-12">
          <div class="panel panel-default">
            <div class="panel-heading">
              ${requestScope.viewtype=="modify"?"学员信息修改":"学员新增"}
            </div>
            <div class="panel-body">
              <div class="row">
                <div class="col-lg-6">
                  <form role="form" method="post" action="${pageContext.request.contextPath}/student.do?action=${requestScope.viewtype=="modify"?"modify":"add"}"><!---设置表单在修改页面只读-->
                    <div class="form-group">
                      <label>学员学号<span class="label" >*</span></label>
                      <input class="form-control" name="studentNo" id="studentNo" placeholder="输入学号" required value="${not empty requestScope.student?requestScope.student.studentNo:""}" ${requestScope.viewtype=="modify"?"readonly":""}>
                      <span ></span>
                    </div>
                    <div class="form-group">
                      <label>密码<span class="label">*</span></label>
                      <input class="form-control" type="password" name="loginPwd" required value="${not empty requestScope.student?requestScope.student.loginPwd:""}">
                    </div>
                    <div class="form-group">
                      <label>学员姓名<span class="label">*</span></label>
                      <input class="form-control" placeholder="Enter text" name="studentName" required value="${not empty requestScope.student?requestScope.student.studentName:""}">
                    </div>
                    <div class="form-group">
                      <label>学员性别<span class="label">*</span></label>
                      <label class="radio-inline">
                        <input type="radio" name="sex" id="optionsRadiosInline1" value="男"${requestScope.student.sex=='男'?"checked":""} >男
                      </label>
                      <label class="radio-inline">
                        <input type="radio" name="sex" id="optionsRadiosInline2" value="女"${requestScope.student.sex=='女'?"checked":""}>女
                      </label>
                    </div>
                    <div class="form-group">
                      <label>年级编号<span class="label">*</span></label>
                      <select class="form-control" name="gradeId" required>
                        <option value="-1">---请选择---</option>
                        <c:forEach items="${requestScope.grades}" var="grade">
                          <option value="${grade.gradeId}" ${requestScope.student.gradeId==grade.gradeId?"selected":''}>${grade.gradeName}</option>
                          </c:forEach>
                      </select>
                    </div>
                    <div class="form-group">
                      <label>联系电话</label>
                      <input class="form-control" name="phone" value="${not empty requestScope.student?requestScope.student.phone:""}">
                    </div>
                    <div class="form-group">
                      <label>地址</label>
                      <input class="form-control" name="address" value="${not empty requestScope.student?requestScope.student.address:""}">
                    </div>
                    <div class="form-group">
                      <label>入学时间</label>
                      <fmt:formatDate value="${requestScope.student.bornDate}" pattern="yyyy-MM-dd" var="bronData"></fmt:formatDate>
                      <input class="form-control" type="date" name="BornDate" value="${not empty requestScope.student?bronData:""}">
                    </div>
                    <div class="form-group">
                      <label>邮箱</label>
                      <input class="form-control" type="email" name="email" value="${not empty requestScope.student?requestScope.student.email:""}">
                    </div>
                    <div class="form-group">
                      <label>身份证号码</label>
                      <input class="form-control" type="text" name="IdentityCard" value="${not empty requestScope.student?requestScope.student.identityCard:''}">
                    </div>
                    <button type="submit" id="addBtn" class="btn btn-default">提交</button>
                    <button type="reset" class="btn btn-default">重置</button>
                  </form>
                 </div>
              </div>
      <footer>
      </footer>
           </div>
          </div>
        </div>
      </div>
</div>
  </div>
</div>

</body>
<script type="text/javascript">
  //ajax异步刷新判断学号是否重复
  $("#studentNo").blur(function (){
    let studentNo = $(this).val();
    let $location = $(this);
      $.ajax({
        url:"${pageContext.request.contextPath}/student.do?action=queryNum",
        type:"post",
        data:{
          studentNo:studentNo
        },
        dataType:"json",
        success:function (data) {
          alert("已获取")
          if (data.result == "true") {
            alert("学号未重复")
            if (! $location.hasClass("hidden"))
              $location.next("span").text("").addClass("hidden")
            $("#addBtn").removeClass("disabled")
            data.result =false;
            }else {
            alert("学号重复")
              $location.next("span").text("输入学号重复").removeClass("hidden")
            $("#addBtn").addClass("disabled")
            }
          }
  })
  })

</script>
</html>
